package tcln.gxtx.client.widget.form;

import java.util.List;

import tcln.gxtx.client.widget.form.model.SimpleComboBoxModel;

/**
 * A very simple combobox which holds a list of {@link SimpleComboBoxModel}. Identifer of each model data in this widget
 * is an {@link Integer}.
 * 
 * @param <ID>
 *            Model id type.
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public class SimpleComboBox<ID> extends AbstractComboBox<SimpleComboBoxModel<ID>> {

    /**
     * Constructs this widget with an empty dropdown list.
     */
    public SimpleComboBox() {
        super();
    }

    /**
     * Constructs this widget with an initial selectable values.
     * 
     * @param values
     */
    public SimpleComboBox(List<SimpleComboBoxModel<ID>> values) {
        super(values);
    }

    /**
     * Sets value for this widget according to model identifier.
     * 
     * @param modelId
     */
    public void setValueById(ID modelId) {
        List<SimpleComboBoxModel<ID>> cbModels = getStore().getModels();
        for (SimpleComboBoxModel<ID> m : cbModels) {
            if (m.getId().equals(modelId)) {
                setValue(m);
                break;
            }
        }
    }
}
